package com.jeesite.modules.exam.quota.web;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.utils.excel.ExcelExport;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.modules.exam.quota.entity.*;
import com.jeesite.modules.exam.quota.service.DcSupExamQuotaOrgService;
import com.jeesite.modules.sys.utils.DictUtils;
import com.jeesite.modules.task.deploy.entity.DcSupTaskInfo;
import com.jeesite.modules.utils.OfficeUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.exam.quota.service.DcSupExamQuotaInfoService;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 考核任务指标表-指标信息Controller
 * @author xhc
 * @version 2022-05-28
 */
@Controller
@RequestMapping(value = "${adminPath}/quota/dcSupExamQuotaInfo")
public class DcSupExamQuotaInfoController extends BaseController {

	@Autowired
	private DcSupExamQuotaInfoService dcSupExamQuotaInfoService;
	@Autowired
	private DcSupExamQuotaOrgService dcSupExamQuotaOrgService;
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupExamQuotaInfo get(String id, boolean isNewRecord) {
		return dcSupExamQuotaInfoService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(DcSupExamQuotaInfo dcSupExamQuotaInfo, Model model) {
		model.addAttribute("dcSupExamQuotaInfo", dcSupExamQuotaInfo);
		return "modules/exam/quota/dcSupExamQuotaInfoList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupExamQuotaInfo> listData(DcSupExamQuotaInfo dcSupExamQuotaInfo, HttpServletRequest request, HttpServletResponse response) {
		dcSupExamQuotaInfo.setPage(new Page<>(request, response));
		Page<DcSupExamQuotaInfo> page = dcSupExamQuotaInfoService.findPage(dcSupExamQuotaInfo);
		return page;
	}

	/**
	 * 获取单项指标考核审核列表数据
	 */
	@RequestMapping("dxzbList")
	@ResponseBody
	public Page<DcSupExamQuotaInfo> dxzbList(DcSupExamQuotaInfo dcSupExamQuotaInfo, HttpServletRequest request, HttpServletResponse response){
        Page<DcSupExamQuotaInfo> page=new Page<>(request, response);
        if("null".equals(dcSupExamQuotaInfo.getQuotaId())){
			return page;
		}
        page = dcSupExamQuotaInfoService.findDcSupExamQuotaInfoList(page,dcSupExamQuotaInfo);
        return page;
	}

	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listKeyData")
	@ResponseBody
	public Page<DcSupExamQuotaInfo> listKeyData(DcSupExamQuotaInfo dcSupExamQuotaInfo, HttpServletRequest request, HttpServletResponse response) {
		dcSupExamQuotaInfo.setPage(new Page<>(request, response));
		Page<DcSupExamQuotaInfo> page = dcSupExamQuotaInfoService.listKeyDataPage(dcSupExamQuotaInfo);
		return page;
	}

	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listDanOrgData")
	@ResponseBody
	public Page<DcSupExamQuotaOrg> listDanOrgData(DcSupExamQuotaOrg dcSupExamQuotaOrg, HttpServletRequest request, HttpServletResponse response) {
		dcSupExamQuotaOrg.setPage(new Page<>(request, response));
		Page<DcSupExamQuotaOrg> page = dcSupExamQuotaInfoService.listDanOrgData(dcSupExamQuotaOrg);
		// 如果结果为空，需要指向前一页
		if (dcSupExamQuotaOrg.getPageNo() > 1 && page.getList() != null && page.getList().size() == 0) {
			int tempPageNo = dcSupExamQuotaOrg.getPageNo();
			dcSupExamQuotaOrg.setPageNo(tempPageNo - 1);
			page = dcSupExamQuotaInfoService.listDanOrgData(dcSupExamQuotaOrg);
		}
		return page;
	}


	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listVersionData")
	@ResponseBody
	public Page<DcSupExamQuotaInfo> listVersionData(DcSupExamQuotaInfo dcSupExamQuotaInfo, HttpServletRequest request, HttpServletResponse response) {
		dcSupExamQuotaInfo.setPage(new Page<>(request, response));
		Page<DcSupExamQuotaInfo> page = dcSupExamQuotaInfoService.findPage(dcSupExamQuotaInfo);
		return page;
	}

	@RequestMapping(value = "form")
	public String form(DcSupExamQuotaInfo dcSupExamQuotaInfo, Model model) {
		if(dcSupExamQuotaInfo.getId() != null){
			DcSupExamQuotaOrg dcSupExamQuotaOrg = new DcSupExamQuotaOrg();
			dcSupExamQuotaOrg.setQuotaInfoId(dcSupExamQuotaInfo.getId());
			List<DcSupExamQuotaOrg> list = dcSupExamQuotaOrgService.findList(dcSupExamQuotaOrg);
			List<String> orgs = new ArrayList<>();
			List<String> orgNames = new ArrayList<>();
			list.forEach(
					x->{
						orgs.add(x.getExameOrg());
						orgNames.add(x.getExameOrgName());
						dcSupExamQuotaInfo.setCurrentYaerGoal(x.getCurrentYaerGoal());
						dcSupExamQuotaInfo.setLastYearComplete(x.getLastYearComplete());
						dcSupExamQuotaInfo.setQuotaUnit(x.getQuotaUnit());
						dcSupExamQuotaInfo.setQuotaWeight(x.getQuotaWeight());
						dcSupExamQuotaInfo.setAssessMethod(x.getAssessMethod());
						dcSupExamQuotaInfo.setLastYearComplete(x.getLastYearComplete());
						dcSupExamQuotaInfo.setLastYaerGoal(x.getLastYaerGoal());
						dcSupExamQuotaInfo.setRemarks(x.getRemarks());
					}
			);
			dcSupExamQuotaInfo.setExameOrgs(StringUtils.join(orgs,","));
			dcSupExamQuotaInfo.setExameOrgNames(StringUtils.join(orgNames,","));
		}
		model.addAttribute("dcSupExamQuotaInfo", dcSupExamQuotaInfo);
		Integer currentYear = Integer.parseInt(DateUtils.getYear());
		model.addAttribute("yearList", OfficeUtil.getYearList(currentYear));
		model.addAttribute("currentYear", currentYear);
		model.addAttribute("quotaType","11");
		return "modules/exam/quota/dcSupExamQuotaInfoForm";
	}

	@RequestMapping(value = "formGj")
	public String formGj(DcSupExamQuotaInfo dcSupExamQuotaInfo, Model model) {
		if(dcSupExamQuotaInfo.getId() != null){
			DcSupExamQuotaOrg dcSupExamQuotaOrg = new DcSupExamQuotaOrg();
			dcSupExamQuotaOrg.setQuotaInfoId(dcSupExamQuotaInfo.getId());
			List<DcSupExamQuotaOrg> list = dcSupExamQuotaOrgService.findList(dcSupExamQuotaOrg);
			List<String> orgs = new ArrayList<>();
			List<String> orgNames = new ArrayList<>();
			list.forEach(
					x->{
						orgs.add(x.getExameOrg());
						orgNames.add(x.getExameOrgName());
						dcSupExamQuotaInfo.setCurrentYaerGoal(x.getCurrentYaerGoal());
						dcSupExamQuotaInfo.setLastYearComplete(x.getLastYearComplete());
						dcSupExamQuotaInfo.setQuotaUnit(x.getQuotaUnit());
						dcSupExamQuotaInfo.setQuotaWeight(x.getQuotaWeight());
						dcSupExamQuotaInfo.setAssessMethod(x.getAssessMethod());
						dcSupExamQuotaInfo.setLastYearComplete(x.getLastYearComplete());
						dcSupExamQuotaInfo.setLastYaerGoal(x.getLastYaerGoal());
						dcSupExamQuotaInfo.setRemarks(x.getRemarks());
					}
			);
			dcSupExamQuotaInfo.setExameOrgs(StringUtils.join(orgs,","));
			dcSupExamQuotaInfo.setExameOrgNames(StringUtils.join(orgNames,","));

		}

		model.addAttribute("dcSupExamQuotaInfo", dcSupExamQuotaInfo);
		Integer currentYear = Integer.parseInt(DateUtils.getYear());
		model.addAttribute("yearList", OfficeUtil.getYearList(currentYear));
		model.addAttribute("currentYear", currentYear);
		return "modules/exam/quota/dcSupExamQuotaInfoFormGj";
	}


	@RequestMapping(value = "formDetail")
	public String formDetail(DcSupExamQuotaInfo dcSupExamQuotaInfo, Model model) {
		if(dcSupExamQuotaInfo.getId() != null){
			DcSupExamQuotaOrg dcSupExamQuotaOrg = new DcSupExamQuotaOrg();
			dcSupExamQuotaOrg.setQuotaInfoId(dcSupExamQuotaInfo.getId());
			List<DcSupExamQuotaOrg> list = dcSupExamQuotaOrgService.findList(dcSupExamQuotaOrg);
			List<String> orgs = new ArrayList<>();
			List<String> orgNames = new ArrayList<>();
			list.forEach(
					x->{
						orgs.add(x.getExameOrg());
						orgNames.add(x.getExameOrgName());
					}
			);
			dcSupExamQuotaInfo.setExameOrgs(StringUtils.join(orgs,","));
			dcSupExamQuotaInfo.setExameOrgNames(StringUtils.join(orgNames,","));
		}

		model.addAttribute("dcSupExamQuotaInfo", dcSupExamQuotaInfo);
		Integer currentYear = Integer.parseInt(DateUtils.getYear());
		model.addAttribute("yearList", OfficeUtil.getYearList(currentYear));
		model.addAttribute("currentYear", currentYear);
		return "modules/exam/quota/dcSupExamQuotaInfoFormDetail";
	}


	/**
	 * 保存数据
	 */
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DcSupExamQuotaInfo dcSupExamQuotaInfo) {
		try {
			if(StringUtils.isNotBlank(dcSupExamQuotaInfo.getQuotaClass())){
				switch (dcSupExamQuotaInfo.getQuotaClass()){
					case "1":
						dcSupExamQuotaInfo.setQuotaType("11");
						break;
					case "2":
						dcSupExamQuotaInfo.setQuotaType("14");
						break;
					case "3":
						dcSupExamQuotaInfo.setQuotaType("13");
						break;
				}
			}
			if(StringUtils.equals(dcSupExamQuotaInfo.getQuotaGroup(),"1")){
				dcSupExamQuotaInfo.setQuotaType("1");
			}
			dcSupExamQuotaInfoService.save(dcSupExamQuotaInfo);
			return renderResult(Global.TRUE, text("保存考核任务指标成功！"));
		} catch (Exception e) {
			e.printStackTrace();
			return renderResult(Global.FALSE, text(e.getMessage()));
		}
	}
	
	/**
	 * 停用数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaInfo:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DcSupExamQuotaInfo dcSupExamQuotaInfo) {
		dcSupExamQuotaInfo.setStatus(DcSupExamQuotaInfo.STATUS_DISABLE);
		dcSupExamQuotaInfoService.updateStatus(dcSupExamQuotaInfo);
		return renderResult(Global.TRUE, text("停用考核任务指标表-指标信息成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequiresPermissions("quota:dcSupExamQuotaInfo:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DcSupExamQuotaInfo dcSupExamQuotaInfo) {
		dcSupExamQuotaInfo.setStatus(DcSupExamQuotaInfo.STATUS_NORMAL);
		dcSupExamQuotaInfoService.updateStatus(dcSupExamQuotaInfo);
		return renderResult(Global.TRUE, text("启用考核任务指标表-指标信息成功"));
	}

	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupExamQuotaInfo dcSupExamQuotaInfo) {
		dcSupExamQuotaInfoService.delete(dcSupExamQuotaInfo);
		return renderResult(Global.TRUE, text("删除考核指标成功！"));
	}


	/**
	 * 保存数据
	 */
	@PostMapping(value = "saveStr")
	@ResponseBody
	public String saveStr( String dcSupExamQuotaInfo) {
		DcSupExamQuotaInfo dcSupExamQuotaInfo1 = JSONObject.parseObject(dcSupExamQuotaInfo, DcSupExamQuotaInfo.class);
		dcSupExamQuotaInfoService.save(dcSupExamQuotaInfo1);
		return renderResult(Global.TRUE, text("保存考核任务指标成功！"));
	}

	/**
	 * 修改被考核单位指标数据
	 */
	@PostMapping(value = "saveStrOrg")
	@ResponseBody
	public String saveStrOrg( String dcSupExamQuotaOrg) {
		DcSupExamQuotaOrg dcSupExamQuotaOrg1 = JSONObject.parseObject(dcSupExamQuotaOrg, DcSupExamQuotaOrg.class);
		dcSupExamQuotaOrgService.save(dcSupExamQuotaOrg1);
		return renderResult(Global.TRUE, text("修改成功！"));
	}

	@RequestMapping(value = "deleteOrg")
	@ResponseBody
	public String deleteOrg(DcSupExamQuotaOrg dcSupExamQuotaOrg) {
		dcSupExamQuotaOrgService.delete(dcSupExamQuotaOrg);
		return renderResult(Global.TRUE, text("删除成功！"));
	}

	/**
	 * 保存数据
	 */
	@PostMapping(value = "saveStrList")
	@ResponseBody
	public String saveStrList( String dcSupExamQuotaInfoList) {
		List<DcSupExamQuotaInfo> dcSupExamQuotaInfos = JSONObject.parseArray(dcSupExamQuotaInfoList, DcSupExamQuotaInfo.class);
		dcSupExamQuotaInfoService.saveStrList(dcSupExamQuotaInfos);
		return renderResult(Global.TRUE, text("保存考核任务指标成功！"));
	}

	//表格导出接口
	@GetMapping("/exportDan")
	public void exportDan(DcSupExamQuotaInfo dcSupExamQuotaInfo,HttpServletResponse response) throws IOException {
		//查询所有用户
		List<DcSupExamQuotaInfoExportDan> list = dcSupExamQuotaInfoService.exportDanList(dcSupExamQuotaInfo);
		list.forEach(
				x->{
					String assessMethod = DictUtils.getDictLabel("dc_exam_assessment", x.getAssessMethod(), "未知");
					String quotaType = DictUtils.getDictLabel("dc_quotaType", x.getQuotaType(), "未知");
					String remarks = DictUtils.getDictLabel("dc_exam_remarks", x.getRemarks(), "未知");
					x.setQuotaType(quotaType);
					x.setAssessMethod(assessMethod);
					x.setRemarks(remarks);
				}
		);
		//在内存操作，写到浏览器
		ExcelWriter writer= ExcelUtil.getWriter(true);
		//自定义标题别名
			writer.addHeaderAlias("quotaType", "类别");
			writer.addHeaderAlias("sortNum", "序号");
			writer.setColumnWidth(1, 10);
			writer.addHeaderAlias("quotaContent", "目标内容");
			writer.setColumnWidth(2, 40);

			writer.addHeaderAlias("exameOrgNames", "被考核单位");
			writer.setColumnWidth(3, 30);

			writer.addHeaderAlias("quotaUnit", "单位");
			writer.addHeaderAlias("quotaWeight", "权数");
			writer.addHeaderAlias("currentYaerGoal", "本年度目标");
			writer.setColumnWidth(6, 30);
			writer.addHeaderAlias("assessMethod", "考核方式");
		    writer.addHeaderAlias("remarks", "备注");

		//默认配置
		writer.write(list,true);
		//设置content—type
		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
		//设置标题
		String fileName= URLEncoder.encode("单项指标信息"+DateUtils.formatDate(new Date(),"yyyyMMddHHmm"),"UTF-8");
		//Content-disposition是MIME协议的扩展，MIME协议指示MIME用户代理如何显示附加的文件。
		response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
		ServletOutputStream outputStream= response.getOutputStream();

		//将Writer刷新到OutPut
		writer.flush(outputStream,true);
		outputStream.close();
		writer.close();
	}

	@GetMapping("/exportKey")
	public void exportKey(DcSupExamQuotaInfo dcSupExamQuotaInfo,HttpServletResponse response) throws IOException {
		//查询所有用户
		List<DcSupExamQuotaInfoExportKey> list = dcSupExamQuotaInfoService.exportKeyList(dcSupExamQuotaInfo);
		list.forEach(
				x->{
					String assessMethod = DictUtils.getDictLabel("dc_exam_assessment", x.getAssessMethod(), "");
					String quotaType = DictUtils.getDictLabel("dc_quotaType", x.getQuotaType(), "未知");
					String remarks = DictUtils.getDictLabel("dc_exam_remarks", x.getRemarks(), "未知");
					x.setQuotaType(quotaType);
					x.setAssessMethod(assessMethod);
					x.setRemarks(remarks);
				}
		);
		//在内存操作，写到浏览器
		ExcelWriter writer= ExcelUtil.getWriter(true);
		//自定义标题别名

			writer.addHeaderAlias("quotaType","类别");
		    writer.setColumnWidth(0, 15);
			writer.addHeaderAlias("sortNum","序号");
			writer.setColumnWidth(1, 10);
			writer.addHeaderAlias("quotaContent","目标内容");
			writer.setColumnWidth(2, 23);


			writer.addHeaderAlias("quotaUnit","单位");
			writer.addHeaderAlias("quotaWeight","权数");
			writer.addHeaderAlias("currentYaerGoal","本年度目标");
		   writer.setColumnWidth(5, 23);
			writer.addHeaderAlias("assessMethod","考核方式");
		    writer.setColumnWidth(6, 15);

			writer.addHeaderAlias("lastYaerGoal","上一年度目标任务");
			writer.setColumnWidth(7, 23);
			writer.addHeaderAlias("lastYearComplete","上一年度完成情况");
			writer.setColumnWidth(8, 23);
			writer.addHeaderAlias("remarks","备注");

		//默认配置
		writer.write(list,true);
		//设置content—type
		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
		//设置标题
		String fileName= URLEncoder.encode("关键指标信息"+DateUtils.formatDate(new Date(),"yyyyMMddHHmm"),"UTF-8");
		//Content-disposition是MIME协议的扩展，MIME协议指示MIME用户代理如何显示附加的文件。
		response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
		ServletOutputStream outputStream= response.getOutputStream();

		//将Writer刷新到OutPut
		writer.flush(outputStream,true);
		outputStream.close();
		writer.close();
	}


	/**
	 * 下载导入单项指标数据模板
	 */
	@RequestMapping(value = "importTemplateDan")
	public void importTemplate(HttpServletResponse response) throws IOException {
		DcSupExamQuotaInfoExportDan dan= new DcSupExamQuotaInfoExportDan();
		dan.setQuotaType("倒扣分项");
		dan.setSortNum(1L);
		dan.setQuotaContent("目标内容");
		dan.setExameOrgNames("市卫生健康委员会");
		dan.setQuotaUnit("单位");
		dan.setQuotaWeight(3D);
		dan.setAssessMethod("实地考核");
		dan.setCurrentYaerGoal("本年度目标");
		dan.setRemarks("新增");
		List<DcSupExamQuotaInfoExportDan> list = ListUtils.newArrayList(dan);
		ExcelWriter writer= ExcelUtil.getWriter(true);
		//自定义标题别名
		writer.addHeaderAlias("quotaType", "类别");
		writer.addHeaderAlias("sortNum", "序号");
		writer.setColumnWidth(1, 10);
		writer.addHeaderAlias("quotaContent", "目标内容");
		writer.setColumnWidth(2, 40);

		writer.addHeaderAlias("exameOrgNames", "被考核单位");
		writer.setColumnWidth(3, 30);

		writer.addHeaderAlias("quotaUnit", "单位");
		writer.addHeaderAlias("quotaWeight", "权数");
		writer.addHeaderAlias("currentYaerGoal", "本年度目标");
		writer.setColumnWidth(6, 30);
		writer.addHeaderAlias("assessMethod", "考核方式");
		writer.addHeaderAlias("remarks", "备注");
		//默认配置
		writer.write(list,true);
		//设置content—type
		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
		//设置标题
		String fileName= URLEncoder.encode("单项指标信息模板","UTF-8");
		//Content-disposition是MIME协议的扩展，MIME协议指示MIME用户代理如何显示附加的文件。
		response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
		ServletOutputStream outputStream= response.getOutputStream();

		//将Writer刷新到OutPut
		writer.flush(outputStream,true);
		outputStream.close();
		writer.close();
	}


	/**
	 * 下载导入关键指标数据模板
	 */
	@RequestMapping(value = "importTemplateKey")
	public void importTemplateKey(HttpServletResponse response) throws IOException {
		DcSupExamQuotaInfoExportKeyUpdate dan= new DcSupExamQuotaInfoExportKeyUpdate();
		//dan.setQuotaType("部门重点工作");
		dan.setSortNum(1L);
		dan.setQuotaContent("目标内容");
		dan.setQuotaUnit("单位");
		dan.setQuotaWeight(3D);
		dan.setCurrentYaerGoal("本年度目标");
		//dan.setAssessMethod("实地考核");
		dan.setLastYaerGoal("上一年度目标任务");
		dan.setLastYearComplete("上一年度目标情况");
		dan.setRemarks("新增");
		List<DcSupExamQuotaInfoExportKeyUpdate> list = ListUtils.newArrayList(dan);
		ExcelWriter writer= ExcelUtil.getWriter(true);
		//自定义标题别名

//		writer.addHeaderAlias("quotaType","类别");
//		writer.setColumnWidth(0, 15);
		writer.addHeaderAlias("sortNum","序号");
		writer.setColumnWidth(1, 10);
		writer.addHeaderAlias("quotaContent","目标内容");
		writer.setColumnWidth(2, 23);


		writer.addHeaderAlias("quotaUnit","单位");
		writer.addHeaderAlias("quotaWeight","权数");
		writer.addHeaderAlias("currentYaerGoal","本年度目标");
		writer.setColumnWidth(5, 23);
//		writer.addHeaderAlias("assessMethod","考核方式");
//		writer.setColumnWidth(6, 15);

		writer.addHeaderAlias("lastYaerGoal","上一年度目标任务");
		writer.setColumnWidth(7, 23);
		writer.addHeaderAlias("lastYearComplete","上一年度完成情况");
		writer.setColumnWidth(8, 23);
		writer.addHeaderAlias("remarks","备注");
		Sheet sheet = writer.getSheet();
		Drawing<?> drawing = sheet.createDrawingPatriarch();
//		//添加批注 类型
//		Comment comment = drawing.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 5, 5));
//		// 输入批注信息
//		Cell cell = writer.getCell(0,0,true);
//		comment.setString(new XSSFRichTextString("关键指标固定类型：部门重点工作"));
//		cell.setCellComment(comment);
//		Comment cellComment = cell.getCellComment();
//		cellComment.setVisible(false);//设置批注默认不显示

		//添加批注 考核方式
//		Comment commentMethod = drawing.createCellComment(new XSSFClientAnchor(6, 0, 6, 0, (short) 1, 6, (short) 5, 10));
//		// 输入批注信息
//		Cell cellMethod = writer.getCell(6,0,true);
//		commentMethod.setString(new XSSFRichTextString("考核方式选项：1.日常考核 2.实地考核"));
//		cellMethod.setCellComment(commentMethod);
//		Comment cellCommentMethod = cellMethod.getCellComment();
//		cellCommentMethod.setVisible(false);//设置批注默认不显示


		//添加批注 备注
		Comment commentRemarks = drawing.createCellComment(new XSSFClientAnchor(9, 0, 9, 0, (short) 1, 4, (short) 5, 8));
		// 输入批注信息
		Cell cellRemarks = writer.getCell(9,0,true);
		commentRemarks.setString(new XSSFRichTextString("备注选项：1.延续 2.新增 3.调整"));
		cellRemarks.setCellComment(commentRemarks);
		Comment cellCommentRemarks = cellRemarks.getCellComment();
		cellCommentRemarks.setVisible(false);//设置批注默认不显示

		//默认配置
		writer.write(list,true);
		//设置content—type
		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
		//设置标题
		String fileName= URLEncoder.encode("关键指标信息模板","UTF-8");
		//Content-disposition是MIME协议的扩展，MIME协议指示MIME用户代理如何显示附加的文件。
		response.setHeader("Content-Disposition","attachment;filename="+fileName+".xlsx");
		ServletOutputStream outputStream= response.getOutputStream();

		//将Writer刷新到OutPut
		writer.flush(outputStream,true);
		outputStream.close();
		writer.close();
	}


	/**
	 * 导入单项数据
	 */
	@ResponseBody
	@PostMapping(value = "importDataDan")
	public String importData(MultipartFile file, String quotaId,String examId,String examYear,String createOrg) {
		try {
			String message = dcSupExamQuotaInfoService.importDataDan(file,quotaId,examId,examYear,createOrg);
			return renderResult(Global.TRUE, "posfull:"+message);
		} catch (Exception ex) {
			return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
		}
	}


	/**
	 * 导入关键数据
	 */
	@ResponseBody
	@PostMapping(value = "importDataKey")
	public String importDataKey(MultipartFile file, String quotaId,String exameOrgs,String exameOrgNames,String examYear) {
		try {
			String message = dcSupExamQuotaInfoService.importDataKey(file,quotaId,exameOrgs,exameOrgNames,examYear);
			return renderResult(Global.TRUE, "posfull:"+message);
		} catch (Exception ex) {
			return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
		}
	}

	/**
	 * 效验单项上报，同一个单位加分指标权数不能大于3
	 */
	@ResponseBody
	@RequestMapping(value = "validationOrg")
	public String validationOrg(DcSupExamQuotaInfo dcSupExamQuotaInfo){
		String message=dcSupExamQuotaInfoService.validationOrg(dcSupExamQuotaInfo);
		return message;
	}

	/**
	 * 引入上一年数据
	 * @param dcSupExamQuotaInfo
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "introPrevious")
	public String introPrevious(DcSupExamQuotaInfo dcSupExamQuotaInfo){
		String msg  = dcSupExamQuotaInfoService.introPrevious(dcSupExamQuotaInfo);
		return renderResult(Global.TRUE, "上一年数据引入成功");
	}
}